import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:baseProjectFlutter/base/mvvm/base_state.dart';

import '../../widgets_common/load_switch/load_switch.dart';
import 'base_view_model.dart';

abstract class BaseMvvmState<T extends BasePage, VM extends BaseViewModel> extends BaseState<T> {
  //主要的ViewMode
  late VM vm;

  BaseMvvmState(VM vm) : vm = Get.put(vm);

  void initState() {
    super.initState();
    vm.lifecycleOwner = this;
    vm.initState();
  }

  @mustCallSuper
  @override
  Widget build(BuildContext context) {
    return super.build(context);
  }

  @override
  Widget createMainWidget(BuildContext context) {
    vm.context = context;
    return super.createMainWidget(context);
    // return MultiProvider(
    //     providers: [ChangeNotifierProvider.value(value: vm)],
    //     child: Consumer<E>(
    //       builder: (context, value, child) {
    //         value.context = context;
    //         if (child != null) return child;
    //         return super.createMainWidget(context);
    //       },
    //     ));
  }

  @override
  LoadStateController get loadStateController => vm.loadStateController;
}
